package com.micro.school.system.service.impl;

import com.micro.school.system.api.domain.vo.SchoolInfoVos;
import com.micro.school.system.domain.SchoolInfo;
import com.micro.school.system.mapper.SchoolInfoMapper;
import com.micro.school.system.service.SchoolInfoService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;


/**
 * (SchoolInfo)表服务实现类
 *
 * @author makejava
 * @since 2025-08-23 17:04:41
 */
@Service("schoolInfoService")
public class SchoolInfoServiceImpl implements SchoolInfoService {

    @Resource
    private SchoolInfoMapper schoolInfoMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SchoolInfo queryById(Integer id) {
        return this.schoolInfoMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param schoolInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SchoolInfo> queryByPage(SchoolInfo schoolInfo, PageRequest pageRequest) {
        long total = this.schoolInfoMapper.count(schoolInfo);
        return new PageImpl<>(this.schoolInfoMapper.queryAllByLimit(schoolInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param schoolInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SchoolInfo insert(SchoolInfo schoolInfo) {
        this.schoolInfoMapper.insert(schoolInfo);
        return schoolInfo;
    }

    /**
     * 修改数据
     *
     * @param schoolInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SchoolInfo update(SchoolInfo schoolInfo) {
        this.schoolInfoMapper.update(schoolInfo);
        return this.queryById(schoolInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.schoolInfoMapper.deleteById(id) > 0;
    }

    @Override
    public SchoolInfoVos queryVosById(Long id) {
        return schoolInfoMapper.queryVosById(id);
    }
}
